package com.yz.vi.admin.controller;

import com.yz.vi.admin.commons.enums.RespondCodeEnum;
import com.yz.vi.commons.helper.ResultUtils;
import com.yz.vi.commons.result.Result;
import com.yz.vi.admin.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: small_woods
 * @Date: 2020/6/16 11:49
 */
@RestController
@Slf4j
@RequestMapping("/test")
public class TestController {

    @Autowired
    private AdminService adminService;


    @PostMapping("/login")
    public Result login(@RequestParam(name = "account", required = false) String account,
                        @RequestParam(name = "password", required = false) String password) {
        String newPassword = adminService.getPwdByAccount(account);
        try{
            if(newPassword.equals(password)){
                return ResultUtils.buildSuccessResult();
            }
            else
                return ResultUtils.buildErrorResult(RespondCodeEnum.userNameAndPasswordError.getCode(), RespondCodeEnum.userNameAndPasswordError.getValue());
        }catch (Exception e){
            return ResultUtils.buildErrorResult(RespondCodeEnum.notFound.getCode(), RespondCodeEnum.notFound.getValue());
        }
    }

}
